<%--
  Created by IntelliJ IDEA.
  User: fan17
  Date: 2021/12/10
  Time: 14:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html class="loginHtml">
<head>
    <meta charset="utf-8">
    <title>登录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="${pageContext.request.contextPath}/static/favicon.ico">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/public.css" media="all" />
</head>
<body class="loginBody">
<form class="layui-form">
    <div class="login_face"><img src="${pageContext.request.contextPath}/static/images/1.gif" class="userAvatar"></div>
    <div class="layui-form-item input-item">
        <label for="staffId">员工工号</label>
        <input type="text"  placeholder="请输入员工工号" name="staffid" autocomplete="off" id="staffid" class="layui-input" lay-verify="required">
    </div>
    <div class="layui-form-item input-item">
        <label for="password">密码</label>
        <input type="password"  placeholder="请输入密码" name="password" autocomplete="off" id="password" class="layui-input" lay-verify="required">
    </div>
    <div class="layui-form-item">
        <button type="button" class="layui-btn layui-block" lay-filter="login" lay-submit>登录</button>
    </div>
</form>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/cache.js"></script>
<script>
    layui.use(['form','layer','jquery'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

        $(".loginBody .seraph").click(function(){
            layer.msg("这只是做个样式，至于功能，你见过哪个后台能这样登录的？还是老老实实的找管理员去注册吧",{
                time:5000
            });
        })

        //登录按钮
        form.on("submit(login)",function(data){
            var regs=/^[0-9]+.?[0-9]*$/;
            if (!regs.test($("#staffid").val())){
                layer.msg("输入的工号格式错误",{icon:5})
            }else {
                $.ajax({
                    url:"${pageContext.request.contextPath}/login/login",
                    data:data.field,
                    type:"post",
                    success:function (result){
                        if (result.code===2000){
                            layer.msg(result.msg,{icon:1});
                            //重定向跳转  无法跳转到WEB-INF下的页面
                            //重定向到控制层----由控制层转发到WEB-INF下的页面
                            location.href="${pageContext.request.contextPath}/main";
                        }else {
                            layer.msg(result.msg,{icon:5});
                        }
                    },
                    dataType:"json"
                });
            }
            return false;
        });


        //表单输入效果
        $(".loginBody .input-item").click(function(e){
            e.stopPropagation();
            $(this).addClass("layui-input-focus").find(".layui-input").focus();
        })
        $(".loginBody .layui-form-item .layui-input").focus(function(){
            $(this).parent().addClass("layui-input-focus");
        })
        $(".loginBody .layui-form-item .layui-input").blur(function(){
            $(this).parent().removeClass("layui-input-focus");
            if($(this).val() != ''){
                $(this).parent().addClass("layui-input-active");
            }else{
                $(this).parent().removeClass("layui-input-active");
            }
        })
    })
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>
<script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget/autoload.js"></script>

</body>
</html>